package net.gz01.wallet.web.controller.admin;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;

import net.gz01.util.ZODate;
import net.gz01.wallet.common.PageRespon;
import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.message.BaseResp;
import net.gz01.wallet.web.config.SystemEnum.Resp;
import net.gz01.wallet.web.controller.BaseController;
import net.gz01.wallet.web.model.ClearingIncome;
import net.gz01.wallet.web.service.ClearingIncomeService;

public class ClearingIncomeController extends BaseController {
	public void search() {
		render("clearing/income/incomeList.html");
	}

	public void listJson() {
		ZOSearchCondition sc = super.getSearchCondition();
		sc.setParameter("type", "0");
		Page<ClearingIncome> pageResult = ClearingIncome.dao.search(sc);
		renderJson(new PageRespon(pageResult));
	}

	/**
	 * 渠道收入
	 */
	public void getChannelIncome() {
		String settleDate = getPara("settleDate");
		if (StrKit.isBlank(settleDate)) {
			renderFail("起始日切日期不能为空");
			return;
		}
		if (settleDate.compareTo(ZODate.getDate()) >= 0) {
			renderFail("提取失败，起始日切日期要小于当天");
			return;
		}
		ClearingIncomeService clearingIncomeService = new ClearingIncomeService();
		BaseResp resp = clearingIncomeService.channelIncome(settleDate);
		if (Resp.Success.getCode().equals(resp.getRespCode())) {
			renderSuccess("提取渠道收入成功");
		} else {
			renderFail(resp.getRespMsg());
		}
	}

	/**
	 * 分润页面
	 */
	public void shareSearch(){
		render("clearing/income/shareList.html");
	}

	public void listShareJson() {
		ZOSearchCondition sc = super.getSearchCondition();
		sc.setParameter("type", "1");
		Page<ClearingIncome> pageResult = ClearingIncome.dao.search(sc);
		renderJson(new PageRespon(pageResult));
	}

	/**
	 * 机构分润
	 */
	public void share(){
		String settleDate = getPara("settleDate");
		if (StrKit.isBlank(settleDate)) {
			renderFail("起始日切日期不能为空");
			return;
		}
		if (settleDate.compareTo(ZODate.getDate()) >= 0) {
			renderFail("提取失败，起始日切日期要小于当天");
			return;
		}
		ClearingIncomeService clearingIncomeService = new ClearingIncomeService();
		BaseResp resp = clearingIncomeService.orgShare(settleDate);
		if (Resp.Success.getCode().equals(resp.getRespCode())) {
			renderSuccess("分润成功");
		} else {
			renderFail(resp.getRespMsg());
		}
	}
}
